import sys
import sysconfig

def merge_sequences(a, b):
    if len(a) != len(b):
        raise ValueError("列表 a 和 b 长度必须相同")
    if not a:
        return [], []
    
    a_merged = []
    b_merged = []
    current_a = a[0]
    current_b = b[0]
    
    for i in range(1, len(a)):
        prev_a, prev_b = a[i-1], b[i-1]
        curr_a, curr_b = a[i], b[i]
        
        # 判断合并条件
        condition1 = (curr_a == curr_b) and (prev_a == prev_b)
        condition2 = (curr_a != 1 and prev_a != 1) and (curr_b == 1 and prev_b == 1)
        condition3 = (curr_a == 1 and prev_a == 1) and (curr_b != 1 and prev_b != 1)
        
        if condition1 or condition2 or condition3:
            current_a *= curr_a
            current_b *= curr_b
        else:
            a_merged.append(current_a)
            b_merged.append(current_b)
            current_a = curr_a
            current_b = curr_b
    
    # 添加最后一个合并组
    a_merged.append(current_a)
    b_merged.append(current_b)
    return a_merged, b_merged

def generate_extension_name(module_name: str) -> str:
    """生成符合 PEP 规范的扩展文件名"""
    # 获取平台和版本信息
    platform = sys.platform
    py_version = f"{sys.version_info.major}{sys.version_info.minor}"
    platform_tag = sysconfig.get_platform().replace("-", "_").replace(".", "_")
    
    # 确定扩展名
    extension = "pyd" if "win" in platform else "so"
    
    # 生成文件名（示例：mymod.cp39-win_amd64.pyd）
    return f"{module_name}.cp{py_version}-{platform_tag}.{extension}"